package com.gkj.blog.util;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.security.PrivateKey;
import java.security.PublicKey;
import java.util.Base64;

public class PasswordUtil {
    private static Logger logger= LoggerFactory.getLogger(PasswordUtil.class);

    private static final PublicKey PUBLIC_KEY=RSAUtil.getPublicKey("MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCk5QaEr41BfEWIXOsDeB2R9kuBYeoHcfMZvl87HS9F55nC+WGr11YyRdskHloRzYKJhjcce+7fQeKY0MrPXCJG40I5Nu/mRU1W68FXcC3y966LBoIkezkMmLUQ6mDj5oky0kuIR0xeAzE5NGTF7LLAT8H06+uBWX3nHJkR70E0pwIDAQAB");

    private static final PrivateKey PRIVATE_KEY=RSAUtil.getPrivateKey("MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAKTlBoSvjUF8RYhc6wN4HZH2S4Fh6gdx8xm+XzsdL0XnmcL5YavXVjJF2yQeWhHNgomGNxx77t9B4pjQys9cIkbjQjk27+ZFTVbrwVdwLfL3rosGgiR7OQyYtRDqYOPmiTLSS4hHTF4DMTk0ZMXsssBPwfTr64FZfeccmRHvQTSnAgMBAAECgYAPjeMNhRnIAZb1g/5PN3dim18H91qCFUefOAv3oYsiBvTEJY4HDar91wUS5SIN59rWaiissSwZNzfOvnNDGCfLbT6DIMbse0PdstgwlmQpsdsyOc5YBjFm5Pc8DRJ9tAIvFjE6WWgeAfcm93LxNAN807FZ37MafWa+NO7ELFlzkQJBANVVO/XhzTN0TAjRalB3ak4G0xdSLSwqR94LGTW7WHM2k+OubHiyyIKP0HtWoC683ceH8LnA1qt6Rg61xhwKmw0CQQDF37j0xlKfX+sNwqWK2jnmKRTmohm9e2J89PYejWlj7DVnBcWllYzNhfTqAZ1Lze4pOTTEuDM7Fxu5yL9lqBGDAkEAs7AMRioALkPZu1+wncBHoRsseCs2c0nVqNhOTqzTbo/c91y2bt+f9iDuaMTpPRTF9UeyYrNj3aGrGr7O9FWWjQJAYBEwMNaggnQFIJch2/n7Jj1Hwnls2cuvk08ytr6dLkAd5TiuLqgexiGFOJ80CPuf5y+46NEtPkEH2vkVw3sHlQJAc2jfHHm6r6hRi5crVqtMPw6jrvSGU+EH0+OAOrxk0L4j80GAzfq8EZLTNucoqDP1MsjzUtNmiCFOrVBn+CYdkQ==");

    public static String decrytByBase64(String s){
        try {
            return new String(RSAUtil.decrypt(Base64.getDecoder().decode(s.getBytes()),PRIVATE_KEY));
        } catch (Exception e) {
            logger.error("解密失败！错误信息：\n{}",e.toString());
        }
        return "";
    }

    public static String encrytByBase64(String s){
        try {
            return new String(Base64.getEncoder().encode(RSAUtil.encrypt(s.getBytes(),PUBLIC_KEY)));
        } catch (Exception e) {
            logger.error("加密失败！错误信息：\n{}",e.toString());
        }
        return "";
    }


}
